Skip to content

fix stream-file urls to use new remoteuri#1984

Merged
sawka merged 5 commits intomainfrom
sawka/fix-web-stream
Feb 18, 2025
Merged

fix stream-file urls to use new remoteuri#1984
sawka merged 5 commits intomainfrom
sawka/fix-web-stream

Conversation

@sawka
Copy link
Member

@sawka sawka commented Feb 18, 2025

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 18, 2025

Walkthrough

The pull request introduces changes across both frontend and backend components. On the frontend, modifications to URL handling in Electron event handlers and markdown utilities adjust how remote file paths are constructed, incorporating file basenames in URLs and using a new URI formatting function. Conditional rendering logic in UI components is refactored by introducing new variables and state atoms, including adjustments for S3 suggestion visibility. Additionally, a new utility function for formatting remote URIs has been added, replacing previous methods of building file URLs. Changes on the backend in the web module add functions for handling local file streaming and modify the logic for processing remote file streams, updating the overall file streaming mechanism. New functions have been introduced, and existing functions have been updated to improve the clarity and functionality of the application. No alterations were made to the exported or public entity signatures, aside from the addition of new variables and properties controlling state.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a97c9ac and 612c48e.

📒 Files selected for processing (1)
  • pkg/remote/fileshare/s3fs/s3fs.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Build for TestDriver.ai
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
pkg/remote/fileshare/s3fs/s3fs.go (1)

777-780: LGTM! The path joining logic has been simplified.

The updated implementation provides a clearer and more straightforward approach to handling path concatenation:

  • When conn.Path is empty or a separator, use the provided parts directly
  • Otherwise, prepend conn.Path to the provided parts

This change aligns well with the PR's objective of fixing stream-file URLs.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (5)
frontend/app/element/markdown-util.ts (1)

162-168:

Details

❓ Verification inconclusive

Verify baseDir usage & consider explicit error handling
Currently, the baseDir is converted to a remote URI using formatRemoteUri. If resolveOpts.baseDir is empty or malformed, the final path might be unexpected. Consider validating baseDir and adding explicit error handling or fallback logic to reduce potential edge cases (e.g., empty baseDir, unusual characters).

You can run the following script to scan for invocation points of resolveRemoteFile to ensure that resolveOpts.baseDir is always valid:


🏁 Script executed:

#!/bin/bash
# Find all usage sites of resolveRemoteFile to confirm correct usage of baseDir
rg -A 4 'resolveRemoteFile\('

Length of output: 754


Action Required: Validate baseDir and Implement Explicit Error Handling

In frontend/app/element/markdown-util.ts (lines 162–168), the code currently converts resolveOpts.baseDir to a remote URI without performing any explicit checks. This may lead to issues if resolveOpts.baseDir is empty or malformed.

  • Please add explicit validation for resolveOpts.baseDir before using it with formatRemoteUri.
  • Consider implementing error handling or fallback logic for edge cases (e.g., empty strings or unexpected characters) to ensure that the joined path and subsequent remote URI are reliable.
  • Note that similar usage patterns are observed in both markdown-util.ts and markdown.tsx (via resolveRemoteFile), suggesting that inconsistent handling of baseDir might propagate unexpected results elsewhere in the app.
frontend/util/waveutil.ts (1)

10-12: Ensure path safety when creating stream-file URLs
Using formatRemoteUri(file, "local") is consistent, but remains vulnerable if file contains special characters or malicious input. Consider sanitizing or validating the path before encoding and appending.

frontend/app/view/term/termsticker.tsx (1)

122-123: Unify local streaming approach with waveutil
Switching to /wave/stream-local-file is consistent with your new endpoint. You might consider leveraging a shared helper (e.g., formatRemoteUri) to uniformly build local vs. remote streaming URLs and reduce duplication across the codebase.

pkg/web/web.go (1)

331-353: Consider improving error message specificity.

While the implementation is solid, the error message could be more specific about what went wrong during streaming.

Consider this improvement:

-        http.Error(w, fmt.Sprintf("error streaming file: %v", err), http.StatusInternalServerError)
+        http.Error(w, fmt.Sprintf("failed to stream file %q: %v", path, err), http.StatusInternalServerError)
emain/emain.ts (1)

242-245: LGTM! URL construction improved with basename in path.

The changes enhance the URL structure by including the file basename in the path segment, making it more identifiable and SEO-friendly. The use of encodeURIComponent for both basename and full path ensures proper URL encoding.

Consider using template literals for better readability:

-    const streamingUrl =
-        getWebServerEndpoint() + "/wave/stream-file/" + baseName + "?path=" + encodeURIComponent(payload.filePath);
+    const streamingUrl = `${getWebServerEndpoint()}/wave/stream-file/${baseName}?path=${encodeURIComponent(payload.filePath)}`;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1929c70 and a97c9ac.

📒 Files selected for processing (11)
  • emain/emain-util.ts (1 hunks)
  • emain/emain.ts (1 hunks)
  • frontend/app/block/blockframe.tsx (2 hunks)
  • frontend/app/element/markdown-util.ts (2 hunks)
  • frontend/app/modals/conntypeahead.tsx (2 hunks)
  • frontend/app/view/preview/directorypreview.tsx (2 hunks)
  • frontend/app/view/preview/preview.tsx (4 hunks)
  • frontend/app/view/term/termsticker.tsx (1 hunks)
  • frontend/types/custom.d.ts (1 hunks)
  • frontend/util/waveutil.ts (2 hunks)
  • pkg/web/web.go (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (go)
  • GitHub Check: Build for TestDriver.ai
🔇 Additional comments (13)
frontend/app/element/markdown-util.ts (1)

7-7: Import aligns with new URI formatting approach
The import correctly references formatRemoteUri from waveutil, ensuring consistent URI handling across the application.

emain/emain-util.ts (1)

89-94: LGTM! URL validation expanded correctly.

The additional URL patterns for streaming endpoints are properly validated, maintaining security while supporting both trailing slash and local file streaming URLs.

pkg/web/web.go (3)

249-256: LGTM! Improved stream handling with proper cleanup.

The function now correctly delegates to handleRemoteStreamFileFromCh and includes stream cancellation functionality.


258-319: LGTM! Well-implemented streaming handler with proper resource management.

The function includes:

  • Proper context cancellation handling
  • Resource cleanup
  • Appropriate header management
  • Graceful error handling

321-329: LGTM! Proper parameter validation and error handling.

The function correctly validates the path parameter and handles local file streaming requests.

frontend/types/custom.d.ts (1)

295-297: LGTM! Well-documented and properly typed property.

The showS3 property is correctly implemented as an optional boolean atom with clear documentation.

frontend/app/modals/conntypeahead.tsx (1)

351-351: LGTM! Proper integration of S3 visibility control.

The changes correctly implement conditional S3 suggestion rendering based on the new showS3 atom.

Also applies to: 440-450

frontend/app/block/blockframe.tsx (1)

244-244: LGTM! Improved button visibility control with clear variable name.

The introduction of showNoWshButton enhances code readability by clearly expressing when the wsh installation button should be shown. The conditions are well-defined and handle edge cases like blank connection names and AWS connections.

Also applies to: 267-267

frontend/app/view/preview/directorypreview.tsx (1)

579-580: LGTM! Improved URI handling with centralized formatting.

The changes enhance consistency by using the centralized formatRemoteUri function for constructing remote URIs during file downloads.

frontend/app/view/preview/preview.tsx (4)

184-184: LGTM! Added state management for S3 visibility.

The introduction of showS3 atom with a default value of true provides clear state management for S3-related UI elements.


942-945: LGTM! Improved URI handling in StreamingPreview.

The changes enhance consistency by using the centralized formatRemoteUri function and properly constructing the URL parameters.


949-949: Use strict equality for MIME type comparison.

The change from loose equality (==) to strict equality (===) for MIME type comparison is a good practice.


1311-1311: LGTM! Simplified exports.

The changes clean up the exports by removing the formatRemoteUri function and only exporting the PreviewView component.

Comment on lines +92 to +102
export function formatRemoteUri(path: string, connection: string): string {
connection = connection ?? "local";
// TODO: We need a better way to handle s3 paths
let retVal: string;
if (connection.startsWith("aws:")) {
retVal = `${connection}:s3://${path ?? ""}`;
} else {
retVal = `wsh://${connection}/${path}`;
}
return retVal;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add path sanitization for remote URI construction
The formatRemoteUri function delegates to custom schemes (aws: vs wsh://), but does not currently sanitize or validate path. Unchecked input might cause incorrect or unintended URIs. Consider adding path checks (removing illegal characters, validating emptiness, etc.) to reinforce correctness and security.

@sawka sawka merged commit e15d38a into main Feb 18, 2025
7 of 8 checks passed
@sawka sawka deleted the sawka/fix-web-stream branch February 18, 2025 01:55
xxyy2024 pushed a commit to xxyy2024/waveterm_aipy that referenced this pull request Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant